%Figure S2
clear variables

load('Fig2_S2_S3_mobility.mat')

%% Figure S2 left panel

figure
ax = usamap('all');
set(ax, 'Visible', 'off')
states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = []; 

for i=1:numel(states)-1 %fills everything leaving DC for last
    if i<9
        states(i).rsq=Rsquared_exp_state(i);
    else
        states(i).rsq=Rsquared_exp_state(i+1);
    end
end

states(51).rsq=Rsquared_exp_state(9);

surfaceColors = makesymbolspec('Polygon', {'rsq', ...
    [0 1], 'FaceColor', flipud(hot(12)) });

% Display the three regions.

geoshow(ax(1), states(indexConus),  'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(2), states(indexAlaska), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
geoshow(ax(3), states(indexHawaii), 'DisplayType','polygon','SymbolSpec', surfaceColors,'DefaultFaceColor','white')
% Hide the frame.
caxis([0 1])
colormap(flipud(hot(12)))

colorbar
for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure S2 right panel
%county level figures could take some time to render.

names = {county_shape.state};
indexHawaii_c = strcmp('Hawaii',names);
indexAlaska_c = strcmp('Alaska',names);
indexConus_c = 1:numel(county_shape);
indexConus_c(indexHawaii_c|indexAlaska_c) = []; 

%county map

figure
ax = usamap('all');
set(ax, 'Visible', 'off')

surfaceColors = makesymbolspec('Polygon', {'r', ...
    [0 1], 'FaceColor', flipud(hot(12)) });

% Display the three regions.
geoshow(ax(1), county_shape(indexConus_c),  'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
% geoshow(ax(2), county_shape(indexAlaska_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
%     'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
geoshow(ax(3), county_shape(indexHawaii_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')

%plot state lines
geoshow(ax(1), states(indexConus),'DisplayType','polygon','DefaultFaceColor','none')
% geoshow(ax(2), states(indexAlaska),'DisplayType','polygon','DefaultFaceColor','none')
geoshow(ax(3), states(indexHawaii),'DisplayType','polygon','DefaultFaceColor','none')

% Hide the frame.
caxis([0 1])
colormap(flipud(hot(12)))
colorbar

for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end
